package com.zh.note.huawei.onehundred.拔河比赛;

/**
 * https://dream.blog.csdn.net/article/details/131912919
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {

    static class Player implements Comparable<Player> {
        int height;
        int weight;

        public Player(int height, int weight) {
            this.height = height;
            this.weight = weight;
        }

        @Override
        public int compareTo(Player other) {
            if (other.height == this.height) { //如果身高相同则按照体重降序排列
                return Integer.compare(other.weight, this.weight);
            }
            return Integer.compare(other.height, this.height); //按照身高降序排列
        }
    }

    public static final int NUM_PLAYERS_TO_DISPLAY = 10;

    public static void main(String[] args) {
        List<Player> players = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.isEmpty()) {
                break; // 如果遇到空行，退出循环
            } else {
                String[] tokens = line.split("\\s+");
                int height = Integer.parseInt(tokens[0]);
                int weight = Integer.parseInt(tokens[1]);
                players.add(new Player(height, weight)); // 解析并将玩家数据添加到列表中
            }
        }
        if (!players.isEmpty()) {
            // 只排序前N个玩家，而不是整个列表
            Collections.sort(players);
            int displayCount = Math.min(NUM_PLAYERS_TO_DISPLAY, players.size());

            // 显示前N个玩家
            for (int i = 0; i < displayCount; i++) {
                Player player = players.get(i);
                System.out.println(player.height + " " + player.weight);
            }
        } else {
            // 处理没有玩家数据的情况
        }
    }
}

